/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
* ModelTreeNode.java
*
* Created on November 28, 2007, 2:32 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
 */
package gui.genomemap.tree;

import genomemap.worker.LHood;

import gui.genomemap.inputModel.AnnealIModel;
import gui.genomemap.inputModel.InputModel;
import gui.genomemap.inputModel.ProgCurveIModel;
import gui.genomemap.outputModel.OutputModel;
import gui.genomemap.view.View;

/**
 *
 * @author stewari1
 */
public class ModelTreeNode extends ViewTreeNode {

    /** Field description */
    private View view = null;

    /** Creates a new instance of ModelTreeNode */
    public ModelTreeNode() {
        setType(TYPE_MODEL);
    }

    /**
     * Constructs ...
     *
     * @param workerOutputModel description
     */
    public ModelTreeNode(OutputModel workerOutputModel) {
        super(workerOutputModel, TYPE_MODEL);
    }

    @Override
    public String toString() {

        String result               = "";
        InputModel workerInputModel = getOutputModel().getInputModel();

        result += "OrderMax-" + workerInputModel.giveMaxOrder();

        if (workerInputModel instanceof AnnealIModel) {

            AnnealIModel annealIModel = (AnnealIModel) workerInputModel;

            if (annealIModel.getLhoodType() == LHood.GLHOOD) result += " " + "Type-" + "GHood";
            if (annealIModel.getLhoodType() == LHood.PLHOOD) result += " " + "Type-" + "PHood";
            if (annealIModel.getLhoodType() == LHood.JLHOOD) result += " " + "Type-" + "JHood";
        }

        if (workerInputModel instanceof ProgCurveIModel) {

            ProgCurveIModel progCurveIModel = (ProgCurveIModel) workerInputModel;

            if (progCurveIModel.getAnnealCriterion() == LHood.GLHOOD)
                result += " " + "Type-" + "GHood";
            if (progCurveIModel.getAnnealCriterion() == LHood.PLHOOD)
                result += " " + "Type-" + "PHood";
            if (progCurveIModel.getAnnealCriterion() == LHood.JLHOOD)
                result += " " + "Type-" + "JHood";
        }

        return result;
    }

    @Override
    public OutputModel getOutputModel() {
        return (OutputModel) getUserObject();
    }

    @Override
    public void referesh() {

        if (view != null) {

            OutputModel outputModel = getOutputModel();

            view.getInputView().setInputModel(outputModel.getInputModel());
            view.getInputView().setEnabledRunModel(outputModel.isEditable());
            view.getOutputView().setOutputModel(outputModel);
        }


        // referesh all the child nodes
        int totalChildren = getChildCount();

        for (int index = 0; index < totalChildren; index++) {

            ((ViewTreeNode) getChildAt(index)).referesh();
        }
    }

    public View getView() {
        return view;
    }

    public void setView(View view) {
        this.view = view;
    }
}
